package com.catmiao.ai.service;

import cn.hutool.http.HttpUtil;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.stereotype.Service;

@Service
public class WeatherService {


    private static final String API_KEY = "1aa6b068093e4dd383a3df963fea6617";

    private static final String API_URL = "https://ph5ctumy5w.re.qweatherapi.com/v7/weather/now?location=%s&key=&s";


    public JsonNode getWeather(String city) throws JsonProcessingException {
        String url = String.format(API_URL, city,API_KEY);

        String response = HttpUtil.get(url);

        JsonNode jsonNode = new ObjectMapper().readTree(response);

        return jsonNode;
    }
}
